package cn.lqz.bucttrain.controller;

import cn.lqz.bucttrain.annotations.PageQueryAutoFill;
import cn.lqz.bucttrain.pojo.dto.RouteCreateOrUpdateDTO;
import cn.lqz.bucttrain.pojo.dto.RoutePageQueryDTO;
import cn.lqz.bucttrain.pojo.vo.OrderVO;
import cn.lqz.bucttrain.pojo.vo.PageResultVO;
import cn.lqz.bucttrain.pojo.vo.ResponseVO;
import cn.lqz.bucttrain.pojo.vo.RouteVO;
import cn.lqz.bucttrain.service.RouteService;
import cn.lqz.bucttrain.utils.ResponseUtils;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/route")
@Validated
public class RouteController {
    @Resource
    private RouteService routeService;

    /**
     * 加载或查询
     * @param routePageQueryDTO
     * @return
     */
    @PostMapping("/loadRouteList")
    @PageQueryAutoFill
    public ResponseVO<PageResultVO> loadRouteList(RoutePageQueryDTO routePageQueryDTO){
        return ResponseUtils.success(routeService.loadRouteList(routePageQueryDTO));
    }

    /**
     * 添加或修改
     * @param routeCreateOrUpdateDTO
     * @return
     */
    @PostMapping("/addOrUpdateRoute")
    public ResponseVO addOrUpdateRoute(@Valid RouteCreateOrUpdateDTO routeCreateOrUpdateDTO){
        routeService.createOrUpdateRoute(routeCreateOrUpdateDTO);
        return ResponseUtils.success();
    }

    /**
     * 删除
     * @param routeId
     * @return
     */
    @PostMapping("/deleteRoute")
    public ResponseVO deleteRoute(@NotNull Long routeId){
        routeService.deleteRoute(routeId);
        return ResponseUtils.success();
    }
    /**
     * 导出路线excel表
     * @param routeVOList
     * @param response
     */
    @PostMapping("/exportRouteExcel")
    public void exportOrderExcel(@RequestBody List<RouteVO> routeVOList, HttpServletResponse response){
        routeService.exportRouteExcel(routeVOList,response);
    }
}
